<template>
  <div id="bar">
    <div class="loading-wrapper" v-show="showLoading">
      <Loading></Loading>
    </div>
    <div class="container" v-show="!showLoading">
      <!-- 面包屑start -->
      <el-breadcrumb separator="/" class="breadCrumb_Box">
        <el-breadcrumb-item><a @click="goUrl('/signatureSuper', 'signatureSuper')">价格</a></el-breadcrumb-item>
        <el-breadcrumb-item>{{c_breadCrumb_name}}</el-breadcrumb-item>
      </el-breadcrumb>
      <!-- 面包屑end -->
      <el-row>
        <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
          <div class="content">
            <div style="padding-bottom: 80px">
              <el-row :gutter="60">
                <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
                  <div class="title1">选择套餐内容</div>
                </el-col>
                <el-col :xs="24" :sm="24" :md="8" :lg="8" :xl="8" v-for="(item, index) in handOutList" :key="index">
                  <div>
                    <div class="input-group" @click="itemSelect(index)">
                      <div class="form-control" :class="getCode == item.code? 'panel1': 'panel2'">
                        <span v-if="type != 4">{{item.title}}</span>
                        <div v-if="type != 4" class="text1">
                          {{item.content}}
                        </div>
                        <img v-if="type!=2&&type!=5" :src="imgList[index]" style="width:80px;margin-left:35px;" />
                      </div>
                      <span class="input-group-btn">
                        <div class="btn btn-default" :class="getCode == item.code? 'box1': 'box2'">
                          <div class="price1">
                            {{ item.price | priceStatus
                            }}<span>元</span>
                          </div>
                        </div>
                      </span>
                    </div>
                  </div>
                </el-col>
              </el-row>
              <el-row>
                <el-col :xs=" 24" :sm="4" :md="4" :lg="4" :xl="4">
                  <div class="title1">购买数量：</div>
                </el-col>
                <el-col :xs="24" :sm="20" :md="20" :lg="20" :xl="20">
                  <el-radio-group v-model="radio" class="title3" @change="numChange">
                    <el-radio :label="1">1个</el-radio>
                    <el-radio v-if="type == 3 || type == 5" :label="10">10个</el-radio>
                    <el-radio v-if="type == 3 || type == 5" :label="50">50个</el-radio>
                    <el-radio v-if="type == 3 || type == 5" :label="100">100个</el-radio>
                    <el-radio v-if="type == 3 || type == 5" :label="500">500个</el-radio>
                  </el-radio-group>
                </el-col>
              </el-row>
              <el-row>
                <el-col :xs="24" :sm="4" :md="4" :lg="4" :xl="4">
                  <div class="title2">支付方式：</div>
                </el-col>
                <el-col :xs="24" :sm="20" :md="20" :lg="20" :xl="20">
                  <div style="margin-top: 70px; margin-left: 20px">
                    <el-button class="wx_button" :class="{payTypeBorder:selectPayType == 'weixin'}"
                      @click="payTypeSelect(1)"><img src="../../../static/price/QianMinTaoCan_WeChat.png" alt=""
                        style="background-color: #00c900;" />&nbsp;微信</el-button>
                    <el-button class="wx_button" :class="{payTypeBorder:selectPayType=='zfb'}"
                      @click="payTypeSelect(2)"><img src="../../../static/price/QianMinTaoCan_Alipay.png" alt=""
                        style="background-color: #5a9ff7;" />&nbsp;支付宝&nbsp;&nbsp;</el-button>
                  </div>
                </el-col>
              </el-row>
              <el-row>
                <!-- <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
                  <div class="count">
                    <div class="price">总支付：<span>{{price | priceStatus}}</span>&nbsp;元<span
                        style="text-decoration:line-through; font-size:14px;">(原价：{{yuanPrice}}元)</span></div>
                    <div>
                      <el-button class="pay_button" @click="gotPay()">去支付</el-button>
                    </div>
                  </div>
                </el-col> -->
                <el-col :xs="24" :sm="3" :md="3" :lg="3" :xl="3">
                  <div class="title2">总支付：</div>
                </el-col>
                <el-col :xs="24" :sm="20" :md="20" :lg="20" :xl="20" class="price">
                  <span>{{price | priceStatus}}</span>&nbsp;元<span
                    style="text-decoration:line-through; font-size:14px;">(原价：{{yuanPrice}}元)</span>
                </el-col>
                <div>
                  <el-button class="pay_button" @click="gotPay()">去支付</el-button>
                </div>
              </el-row>
            </div>
          </div>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
  import Loading from '@/components/common/laoding'
  import filters from "../../utils/filters";
  export default {
    filters: filters,
    //import引入的组件需要注入到对象中才能使用
    components: {
      Loading
    },
    data() {
      //这里存放数据
      return {
        radio: 1, //默认选中第一个单选框
        color: "", //套餐背景颜色
        handOutList: [], //接收数据
        getCode: null, //接收code
        selectPayType: 'weixin', //weixin,zfb
        getPayWay: 1, //1微信 2支付宝
        buyNum: 1, //数量
        price: 300, //价格
        yuanPrice: 0,
        type: 2, //2（分发套餐），1（企业签名套餐），3（超级签名套餐），4（会员套餐）
        showLoading: true, // 显示loading
        orderID: {},
        c_breadCrumb_name: '购买',
        appID: '',
        selectItem: {},
        imgList: ["/static/price/taocan_cjhy.png", "/static/price/taocan_zjhy.png", "/static/price/taocan_gjhy.png"],
      };
    },
    //监听属性 类似于data概念
    computed: {},
    //监控data中的数据变化
    watch: {},
    //方法集合
    methods: {
      //选择支付方式
      payTypeSelect(type) {
        this.selectPayType = type == 1 ? "weixin" : "zfb";
        this.getPayWay = type;

      },
      //选择支付金额
      itemSelect(index) {
        let item = this.handOutList[index]; //选中项
        this.selectItem = item;
        this.getCode = item.code;
        this.price = item.price;
        this.yuanPrice = this.buyNum * this.selectItem.price;
        this.getPrice();
      },
      //选择数量
      numChange(e) {
        // console.log(e);
        this.buyNum = e;
        this.getPrice();
        this.yuanPrice = this.buyNum * this.selectItem.price;
      },
      //提交支付
      gotPay() {
        var params = new URLSearchParams();
        params.append("payIndex", this.getCode);
        params.append("num", this.buyNum);
        params.append("paytype", this.getPayWay);
        this.$post(this.API.Payment, params).then((res) => {
          let data = res.data;
          this.orderID = data.orderid;
          // console.log(res);
          if (this.selectPayType == "zfb") {
            document.querySelector("body").innerHTML = res.data; //查找到当前页面的body，将后台返回的form替换掉body内容
            document.forms[0].submit();
          } else {
            //微信
            this.$router.push({
              path: "/wechat",
              name: "wechat",
              query: {
                orderID: this.orderID,
                type: this.$route.query.type,
                code: this.$route.query.code,
                appID: this.$route.query.appID
              },
            });
          }
        });
      },

      getPrice() {
        var params = new URLSearchParams();
        params.append("code", this.getCode);
        params.append("num", this.buyNum);
        this.$post(this.API.payCompute, params).then((res) => {
          let data = res.data;
          this.price = data.money
        })
      },
      //数据
      getList() {
        var params = new URLSearchParams();
        params.append("type", this.$route.query.type);
        this.$post(this.API.Price_payindex, params).then((res) => {
          this.showLoading = false
          let data = res.data;
          this.handOutList = data;
          let item = this.handOutList[1]; //选中项
          this.selectItem = item;
          this.yuanPrice = this.buyNum * this.selectItem.price;
        });
      },
    },
    //生命周期 - 创建完成（可以访问当前this实例）
    created() {
      this.getList();
      this.getCode = this.$route.query.code; //code初始值
      this.type = this.$route.query.type;
      console.log(this.type, "8");
      this.getPrice();
    },
    //生命周期 - 挂载完成（可以访问DOM元素）
    mounted() {},
  };

</script>
<style scoped>
  /* 面包屑  */
  .breadCrumb_Box {
    margin-top: 30px;
    margin-bottom: 20px;
  }

  a {
    text-decoration: none;
  }

  div>>>.pay_button {
    width: 180px;
    height: 50px;
    background-image: linear-gradient(to right, #f59833, #f95810);
    border-radius: 4px;
    font-size: 18px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #FFFFFF;
    line-height: 18px;
    padding: 0px;
    border: none;
    margin-left: 150px;
    margin-top: 40px;
  }

  .price {
    font-size: 16px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #fff;
    line-height: 16px;
    margin-top: 80px;
    margin-bottom: 10px;
    margin-left: 4px;
  }

  .price span {
    font-size: 26px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #F65D26;
    line-height: 20px;
  }

  .count {
    display: flex;
    flex-direction: column;
    margin-left: 30px;
    margin-top: 60px;
    margin-bottom: -40px;
  }

  div>>>.wx_button {
    border: 2px solid #FF7226;
  }

  div>>>.wx_button {
    width: 180px;
    height: 80px;
    background: #272727;
    border-radius: 4px;
    border: 0px;
    font-size: 16px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #fff;
    line-height: 20px;
  }

  div>>>.wx_button img {
    margin-top: -4px;
    margin-left: -8px;
    display: inline-block;
    width: 25px;
    height: 25px;
    border-radius: 50%;
  }

  div>>>.wx_button span {
    margin-top: -px;
  }

  div>>>.buttonurl {
    background: #03a0ec;
    border-radius: 8px;
    color: #fff;
    width: 114px;
    height: 40px;
    font-size: 16px;
    text-align: center;
  }

  .but {
    margin-left: 120px;
    margin-top: -35px;
  }

  .textOne {
    font-size: 16px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #000000;
    line-height: 20px;
  }

  .textOne span {
    font-size: 26px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #f65d26;
    line-height: 20px;
    margin: 0px 5px 0px 0px;
  }

  .textTwo {
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #5a5e66;
    line-height: 14px;
    margin: 18px 0px 18px 0px;
  }

  .wxicon {
    margin: -5px 3px 0px 0px;
  }

  .wechat {
    font-size: 20px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #000000;
    line-height: 20px;
    margin: -28px 0px 0px 35px;
  }

  /* 支付方式选中 start*/
  div>>>.payTypeBorder {
    border: 2px solid #FF7226;
  }

  /* 支付方式选中 end*/
  #bar {
    width: 100%;
    min-height: 472px;
    background-color: #000;
    overflow: hidden;
  }

  .content {
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
    margin-bottom: 30px;
    background-color: #0f0f0f;
  }

  .breadcrumb {
    background: none;
  }

  .title1 {
    font-family: "苹方-简 中黑体";
    font-size: 16px;
    font-weight: bolder;
    padding: 40px 0px 0px 30px;
    color: #fff;
  }

  .title2 {
    font-family: "苹方-简 中黑体";
    font-size: 16px;
    font-weight: bolder;
    padding: 80px 0px 0px 30px;
    color: #fff;
  }

  .title3 {
    font-family: "苹方-简 中黑体";
    font-size: 16px;
    font-weight: bolder;
    padding: 40px 0px 0px 0px;
    margin-left: 25px;
    margin-right: 10px;
  }

  .title4 {
    padding: 60px 0px 0px 30px;
  }

  .title5 {
    padding: 85px 0px 0px 30px;
  }

  .textTwo1 {
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #5a5e66;
    line-height: 14px;
    margin: 18px 0px 18px 0px;
  }

  .wxicon1 {
    margin: -5px 3px 0px 0px;
  }

  .wechat1 {
    font-size: 20px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #000000;
    line-height: 20px;
    margin: -28px 0px 0px 35px;
  }

  .border {
    display: flex;
  }

  .panel1 {
    font-family: PingFangSC-Regular, PingFang SC;
    height: 100px;
    background: #ee792d;
    border-radius: 0px;
    margin-left: 20px;
    margin-right: 20px;
    margin-top: 20px;
    color: #fff;
    display: flex !important;
    flex-direction: column;
    justify-content: center;
    border: none;
  }

  .panel2 {
    height: 100px;
    background: #1d1d1d;
    border-radius: 0px;
    margin-left: 20px;
    margin-right: 20px;
    margin-top: 20px;
    color: #fff;
    display: flex !important;
    flex-direction: column;
    justify-content: center;
    border: none;
  }

  .box1 {
    width: 126px;
    height: 100px;
    background: #f95a11;
    border-radius: 0px;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    margin-top: 20px;
    margin-right: 20px;
    border: none;
  }

  .box2 {
    width: 126px;
    height: 100px;
    background: #343434;
    border-radius: 0px;
    border: 0px;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    margin-top: 20px;
    margin-right: 20px;
  }

  .text1 {
    font-family: "苹方-简 中黑体";
    font-size: 16px;
  }

  .text2 {
    font-family: "苹方-简 中黑体";
    font-size: 16px;
    color: #757575;
  }

  .price1 {
    font-size: 30px;
    color: #fff;
  }

  .price1 span {
    font-size: 14px;
    margin: 0px 5px;
    color: #fff;
  }

  .box1 .ran {
    color: #fff;
  }

  .price2 {
    font-size: 30px;
    color: #000;
  }

  .price2 span {
    font-size: 14px;
    margin: 0px 5px;
    color: #000;
  }

  .ran {
    color: #000;
  }

  .pay {
    display: flex;
    flex-direction: row;
    margin-left: 10px;
  }

  div>>>.el-radio__input.is-checked .el-radio__inner {
    border-color: #ff720b;
    background: #ff720b;
  }

  div>>>.el-radio__input.is-checked+.el-radio__label {
    color: #ff720b;
  }

  @media (max-width: 375px) {

    .panel1,
    .panel2 {
      font-size: 12px;
    }

    .text1,
    .text2 {
      font-size: 14px;
    }
  }

  .breadCrumb_Box>>>.el-breadcrumb__inner a {
    color: #ee7829;
  }

  .breadCrumb_Box>>>.el-breadcrumb__item .el-breadcrumb__separator {
    color: #fff;
  }

  .breadCrumb_Box>>>.el-breadcrumb__item .el-breadcrumb__inner {
    color: #fff;
  }

</style>
